<?php 
require_once ROOT_PATH . '/lib/models/hrfunct/EmpInfo.php';
require_once ROOT_PATH . '/lib/models/skillmatrix/SkillIndividual.php';
$empList = EmpInfo::getEmpSkillInfo();
$userID = (int)$_SESSION['empID'];
$baseURL = './CentralController.php?skillMatrixcode=SkillMatrix';
$skillIndividual = $records['skillIndividual'];
$skillMatrix = $records['skillMatrix'];
$userSkills = SkillIndividual::getEmpSkillUsers($userID);

function getValue($list,$expertiseid=null){
	if($expertiseid){
		foreach($list as $item){
			if($item[1]==$expertiseid)
				return $item;
		}
		return null;
	}else{
		return null;
	}
}

function countRowSpan($list,$groupid){
	$count =0;
	for($i = 0; $i<count($list);$i++){
		if($groupid == $list[$i][2])
			$count++;
	}
	return $count;
}

?>
<script type="text/javascript">
	
function addSave() {
	var strYear = document.getElementById("numofyear");
	
	
	if(isNumeric(strYear, "# Year in IT field must be a number")){
		if(strYear.value >=100){
			alert("# Year in IT field must be less than 100");
			return false;
		}else{
			document.declare.submit();
		}
	}else{
		return false;
	}
}
function refresh() {		
		document.declare.action = '<?php echo $baseURL;?>&action=Declare';
		document.declare .submit();
}
function isNumeric(elem, helperMsg){
	var numericExpression = /^\s*(\+|-)?((\d+(\.\d+)?)|(\.\d+))\s*$/;

	if(elem.value.match(numericExpression)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}


</script>
<h2><?php echo "Skill Matrix"; ?><hr/></h2>
<?php if (isset($_GET['message'])) {

		$expString  = $_GET['message'];
?>
		<font size="-1" face="Verdana, Arial, Helvetica, sans-serif">
<?php echo $expString; ?>
		</font>
<?php }	?>
<form id="declare" name="declare" method="post"  action="<?php echo $_SERVER['PHP_SELF']; ?>?skillMatrixcode=SkillMatrix&action=saveDeclare">

<table width="200"  border="0" cellpadding="0" cellspacing="0" style="margin-bottom:10px;float: left;" >
	 <thead>
	  	<tr>
			<th class="tableTopLeft"></th>    	
	    	<th class="tableTopMiddle" ></th>
			<th class="tableTopRight"></th>
		</tr>
		<tr>
			<th class="tableMiddleLeft"></th>		
	    	<th class="tableMiddleMiddle" ><?php echo "General info"; ?></th>    	
			<th class="tableMiddleRight"></th>
		</tr>
		
	  </thead>
  <tbody > 
	<tr>
		<td class="tableMiddleLeft"></td>
		<td>
			<table>
				<tr>				  	
				  	<td align="right">
				  		# Year in IT field
				  	</td>
				  	<td>
				  		<input type="text" name="numofyear" id="numofyear" value="<?php echo $skillIndividual->getSkillIndividualNumOfYear(); ?>" size="2"/><span> year(s)</span>
				  	</td>				  	
				  	</tr>
				    <tr>				  	
				  	<td align="right">
				  		Work abroad
				  	</td>
				  	<td>
				  		<select name="work_abroad" id="work_abroad">
				  			<?php if($skillIndividual->getSkillIndividualWorkAbroad()=="No"){ ?>					
									<option selected value="No">No</option>
									<option value="Yes">Yes</option>
							<?php }else{ ?>
									<option value="No">No</option>
									<option selected value="Yes">Yes</option>
							<?php } ?>		
						</select>
				  	</td>				  	
				  </tr>
				   <tr>				  	
				  	<td align="right">
				  		Expertise
				  	</td>
				  	<td height="90">
				  		<select name="expertise" id="expertise" onchange="refresh();">
				  			<?php if(isset($records['expertise'])){ ?>
				  				<?php if($records['expertise']==1){ ?>					
										<option selected="selected" value="1">Dev</option>
										<option value="2">QA</option>
								<?php }else{ ?>
										<option value=1>Dev</option>
										<option selected="selected" value="2">QA</option>
								<?php } ?>
				  			<?php }else{ ?>
					  			<?php if($skillIndividual->getSkillIndividualExpertise()==1){ ?>					
										<option selected="selected" value="1">Dev</option>
										<option value="2">QA</option>
								<?php }else{ ?>
										<option value="1">Dev</option>
										<option selected="selected" value="2">QA</option>
								<?php } ?>
							<?php } ?>					
									
						</select>
				  	</td>
				  	
				  </tr>	
			</table>
		</td>
		<td class="tableMiddleRight"></td>
		</tr>
		  </tbody> 
  <tfoot>  	
  	<tr>
		<td class="tableBottomLeft"></td>    	
    	<td class="tableBottomMiddle"></td>    		
		<td class="tableBottomRight"></td>
	</tr>
  </tfoot>
</table>
		<table width="565" border="0" cellpadding="0" cellspacing="0" style="margin-bottom:10px;float: right;" >
	 <thead>
	  	<tr>
			<th class="tableTopLeft"></th>    	
	    	<th class="tableTopMiddle" ></th>
	    	
			<th class="tableTopRight"></th>
		</tr>
		<tr>
			<th class="tableMiddleLeft"></th>		
	    	<th class="tableMiddleMiddle" >Legend</th>    	
			<th class="tableMiddleRight"></th>
		</tr>
		
	  </thead>
  	  <tbody>
  		<tr> 
  		<td class="tableMiddleLeft"></td>	
		<td>
			<table cellpadding="0" cellspacing="0">
				<tr>
					<td style="padding: 2px;">
						<span style="font-weight:bold;">1 - Introductory:</span> Demonstrates introductory understanding and ability and, with guidance, applies the skill in a few simple situations.
					</td>
				</tr>
				<tr>
					<td style="padding: 2px;">
						<span style="font-weight:bold;">2 - Basic:</span> Demonstrates basic knowledge and ability and, with guidance, can apply the skill in common situations that present limited difficulties.
					</td>
				</tr>
				<tr>
					<td style="padding: 2px;">
						
						<span style="font-weight:bold;">3 - Intermediate:</span> Demonstrates solid knowledge and ability, and can apply the skill with minimal or no guidance in the full range of typical situations. Would require guidance to handle novel or more complex situations.
					</td>
				</tr>
				<tr>
					<td style="padding: 2px;">
						
						<span style="font-weight:bold;">4 - Advanced:</span> Demonstrates advanced knowledge and ability, and can apply the skill in new or complex situations. Guides other professionals.
					</td>
				</tr>
				<tr>
					<td style="padding: 2px;">
						
						<span style="font-weight:bold;">5 - Expert:</span> Demonstrates expert knowledge and ability, and can apply the skill in the most complex situations. Develops new approaches, methods or policies in the area. Is recognized as an expert, internally and/or externally. Leads the guidance of other professionals.
					</td>
				</tr>
			
			</table>
		</td>
		<td class="tableMiddleRight"></td>
	</tr>					
  </tbody> 
  <tfoot>  	
  	<tr>
		<td class="tableBottomLeft"></td>    	
    	<td class="tableBottomMiddle"></td>    		
		<td class="tableBottomRight"></td>
	</tr>
  </tfoot>
</table>

 
<table width="770" border="0" cellpadding="0" cellspacing="0" style="float: left;">
   <thead>
  	<tr>
		<th class="tableTopLeft"></th>    	
    	<th class="tableTopMiddle" ></th>
    	<th class="tableTopMiddle" ></th>
    	<th class="tableTopMiddle" ></th>
		<th class="tableTopRight"></th>
	</tr>
	
	<tr>
		<th class="tableMiddleLeft"></th>		
    	<th class="tableMiddleMiddle"  ><?php echo "Group"; ?></th>
    	<th class="tableMiddleMiddle"  width="200" ><?php echo "Skill Expertise"; ?></th>
		<th class="tableMiddleMiddle" >Proficiency Level 	</th>	
		<th class="tableMiddleRight"></th>
	</tr>
  </thead>
  <tbody>
 <?php if (count($skillMatrix)>0) {
 	$j = countRowSpan($skillMatrix, $skillMatrix[0][2]);
 	$cssClass = 'odd';
  	for($m=0;$m<count($skillMatrix);$m++) {
  		$rowspan = countRowSpan($skillMatrix, $skillMatrix[$m][2]);
  		if($j != $rowspan) 
  		{ 
  			$j = $rowspan;
  			if($cssClass == 'odd')
  				$cssClass = 'even';
  			else
  				$cssClass = 'odd';	 
  		}
  	?>
 	<tr style="height: 30px;" >
	 	<td class="tableMiddleLeft"></td> 		
	 		<?php if($m==0){ ?> 			
				<td class = "<?php echo $cssClass; ?>"  style="text-align:left;vertical-align:middle" rowspan="<?php echo $rowspan; ?>"><?php echo $skillMatrix[$m][3]; ?></td>
			<?php }elseif($skillMatrix[$m-1][2]!=$skillMatrix[$m][2]){?>			 
				<td class = "<?php echo $cssClass; ?>" style="text-align:left;vertical-align:middle" rowspan="<?php echo $rowspan; ?>"><?php echo $skillMatrix[$m][3]; ?></td>
				
				<?php } ?>  		
	  		<td class = "<?php echo $cssClass; ?>" >
	  			<?php echo $skillMatrix[$m][1]; ?>
	  		</td>
	  		<td class = "<?php echo $cssClass; ?>" style="text-align: center;vertical-align:middle">
	  			<?php $value = getValue($userSkills,$skillMatrix[$m][0]); ?>	  			
	  			<span >
	  			<input title="Introductory" <?php echo($value[2]==1?"checked":''); ?> type="radio" name="skill<?php echo $skillMatrix[$m][0] ?>" value="1"/> <span title="Introductory" style="padding-bottom:2px;font-weight:bold;">1</span>
	  			<input title="Basic" <?php echo($value[2]==2?"checked":''); ?> type="radio" name="skill<?php echo $skillMatrix[$m][0]?>" value="2"/> <span title="Basic" style="font-weight:bold;">2</span>
	  			<input title="Intermediate" <?php echo($value[2]==3?"checked":''); ?> type="radio" name="skill<?php echo $skillMatrix[$m][0] ?>" value="3"/> <span title="Intermediate" style="font-weight:bold;">3</span>
	  			<input title="Advanced" <?php echo($value[2]==4?"checked":''); ?> type="radio" name="skill<?php echo $skillMatrix[$m][0] ?>" value="4"/> <span title="Advanced" style="font-weight:bold;">4</span>
	  			<input title="Expert" <?php echo($value[2]==5?"checked":''); ?> type="radio" name="skill<?php echo $skillMatrix[$m][0] ?>" value="5"/> <span title="Expert" style="font-weight:bold;">5</span>
	  			</span>
	  		</td>
  		<td class="tableMiddleRight"></td>
  	</tr>	
 	
  <?php } ?>
<?php } ?>			
  </tbody>
 
  <tfoot>
  	<tr>
			<td class="tableMiddleLeft"></td>
			<td ></td>
			<td >
				<input type="image"  onclick="return addSave();" name="btnSave" alt="Save"
					   src="../../themes/beyondT/pictures/btn_save.gif" />
			</td>
			<td ></td>
			<td class="tableMiddleRight"></td>
	</tr>
  	<tr>
		<td class="tableBottomLeft"></td>
		<td class="tableBottomMiddle"></td>
		<td class="tableBottomMiddle"></td>	
    	<td class="tableBottomMiddle"></td>	
		<td class="tableBottomRight"></td>
	</tr>
  </tfoot>
  
</table>
</form>

